package com.zznj.xzjc.activity;

import android.content.Context;
import android.graphics.Typeface;
import android.view.KeyEvent;
import android.view.View;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.fragment.app.Fragment;
import androidx.viewpager.widget.ViewPager;

import com.flyco.tablayout.SlidingTabLayout;
import com.flyco.tablayout.listener.OnTabSelectListener;
import com.google.gson.Gson;
import com.zznj.xzjc.R;
import com.zznj.xzjc.base.BaseActivity;
import com.zznj.xzjc.fragment.index.AjcxDsjjsFragment;
import com.zznj.xzjc.fragment.index.HdlxFragment;
import com.zznj.xzjc.fragment.index.XsglFragment;
import com.zznj.xzjc.net.SharedHelper;
import com.zznj.xzjc.net.entity.DictionaryBean;
import com.zznj.xzjc.net.entity.LoginBean;
import com.zznj.xzjc.view.StatusBarUtil;
import com.zznj.xzjc.widget.FragmentAda;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;
import butterknife.Unbinder;

/**
 * 描述：线索发现
 */
public class ActivityHdlxMain extends BaseActivity {
    @BindView(R.id.stl_main)
    SlidingTabLayout stlMain;
    @BindView(R.id.vp)
    ViewPager vp;
    Unbinder unbinder;

    @Override
    protected int getLayoutId() {
        return R.layout.gyss_activity_hdlx_main_layout;
    }
    private LoginBean user;
    private int selectIndex = 0;
    private String key;

    @Override
    public void initView() {
        selectIndex = getIntent().getExtras().getInt("index");
        key = getIntent().getExtras().getString("key");
        user = new Gson().fromJson(SharedHelper.readValueByKeyForString(mContext, "Member"), LoginBean.class);
        setTitle("互动连线");
        init();
    }

    private String[] mTitle = {"待回复", "已回复"};
    private ArrayList<Fragment> arrayList = null;

    private void init() {
        arrayList = new ArrayList<>();
        arrayList.add(HdlxFragment.getInstance(0));
        arrayList.add(HdlxFragment.getInstance(1));

        stlMain.setOnTabSelectListener(new OnTabSelectListener() {
            @Override
            public void onTabSelect(int position) {
                selectIndex = position;
                for (int i = 0; i < arrayList.size(); i++) {
                    if (i == position) {
                        stlMain.getTitleView(position).setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));
                    } else {
                        stlMain.getTitleView(i).setTypeface(Typeface.defaultFromStyle(Typeface.NORMAL));
                    }
                }

            }

            @Override
            public void onTabReselect(int position) {

            }
        });
        vp.setAdapter(new FragmentAda(getSupportFragmentManager(), arrayList, null));
        vp.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {
                selectIndex = position;
                for (int i = 0; i < arrayList.size(); i++) {
                    if (i == position) {
                        stlMain.getTitleView(position).setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));
                    } else {
                        stlMain.getTitleView(i).setTypeface(Typeface.defaultFromStyle(Typeface.NORMAL));
                    }
                }
            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });
        stlMain.setViewPager(vp, mTitle);


        stlMain.getTitleView(selectIndex).setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));
        vp.setCurrentItem(selectIndex);
    }

    private List<DictionaryBean> fromList;

    @Override
    protected void initData() {
    }
}
